package com.alt.handler;

import java.io.Serializable;

import com.alt.manager.ALTPTCMgr;
import com.alt.models.TransactionData;
import com.alt.models.UserData;
import com.alt.models.UserData2;
import com.alt.processor.CMProcessor;

import android.os.Bundle;

public class CMCmdHandler extends BaseCmdHandler {

	public final static int COMMAND_INIT_APP = 900;
	public final static int COMMAND_VALIDATE_USER = 301;
	public final static int COMMAND_CHECK_PUT_METHOD = 302;
	public final static int COMMAND_GET_ADS_LIST = 303;
	public final static int COMMAND_GET_ADS_LIST_BY_USERID = 304;
	public final static int COMMAND_GET_ADS_IMAGE_LIST = 305;
	public final static int COMMAND_UPDATE_PROFILE_PICTURE = 306;
	public final static int COMMAND_UPDATE_TRANSACTION = 307;
	public final static int COMMAND_GET_TRANSACTION_lIST_BY_USERID = 308;
	
	public final static int COMMAND_REGISTER_NEW_ACCOUNT = 309;
	
		
	@Override
	public Bundle commandHandler(int command, Bundle cmdData) {
		CMProcessor connector = new CMProcessor();

		Bundle resultData = new Bundle();
		
		Object result = null;

		switch (command) {

		case COMMAND_INIT_APP:
			break;
			
		case COMMAND_VALIDATE_USER:{
			String username = cmdData.getString("username");
			String password = cmdData.getString("password");
			String deviceid = cmdData.getString("deviceid");
			String deviceip = cmdData.getString("deviceip");
			String accounttype = cmdData.getString("accounttype");
			
			result = connector.mobilelogin(username, password, deviceid, deviceip, accounttype);
			resultData.putSerializable(ALTPTCMgr.REST_OBJECT_RETURN,(Serializable) result);
		 }
			break;
			
		case COMMAND_CHECK_PUT_METHOD:{
			UserData uData = (UserData) cmdData.getSerializable(ALTPTCMgr.REST_OBJECT_PUT);
			result = connector.CheckPutMethod(uData);
			resultData.putSerializable(ALTPTCMgr.REST_OBJECT_RETURN, (Serializable) result);
		}
			break;
			
		case COMMAND_GET_ADS_LIST:{			
			result = connector.getAdsList();
			resultData.putSerializable(ALTPTCMgr.REST_OBJECT_RETURN, (Serializable) result);
		}
			break;
			
		case COMMAND_GET_ADS_LIST_BY_USERID:{		
			String userid = cmdData.getString("userid");
			String loadeditemcount = cmdData.getString("loadeditemcount");
			result = connector.getAdsListByUserid(userid,loadeditemcount);
			resultData.putSerializable(ALTPTCMgr.REST_OBJECT_RETURN, (Serializable) result);
		}
			break;
		case COMMAND_GET_ADS_IMAGE_LIST:{
			String pos = cmdData.getString("AdsID");
			result = connector.getAdsListImage(pos);
			resultData.putSerializable(ALTPTCMgr.REST_OBJECT_RETURN, (Serializable) result);
		}
			break;
			
		case COMMAND_UPDATE_PROFILE_PICTURE:{
			UserData2 uData = (UserData2) cmdData.getSerializable(ALTPTCMgr.REST_OBJECT_PUT);
			result = connector.updateUserProfile(uData);
			resultData.putString(ALTPTCMgr.REST_OBJECT_RETURN, (String)result);
		}
			break;
			
		case COMMAND_UPDATE_TRANSACTION:{
			TransactionData trans = (TransactionData) cmdData.getSerializable(ALTPTCMgr.REST_OBJECT_PUT);
			result = connector.updateTransaction(trans);
			resultData.putString(ALTPTCMgr.REST_OBJECT_RETURN, (String)result);
		}
			break;
			
		case COMMAND_GET_TRANSACTION_lIST_BY_USERID:{
			String userid = cmdData.getString("userid");
			result = connector.getTransactionByUserId(userid);
			resultData.putSerializable(ALTPTCMgr.REST_OBJECT_RETURN, (TransactionData[])result);
		}
			break;
			
		case COMMAND_REGISTER_NEW_ACCOUNT:{
			String username = cmdData.getString("username");
			String password = cmdData.getString("password");
			String deviceid = cmdData.getString("deviceid");
			result = connector.mobileregister(username, password, deviceid);
			resultData.putString(ALTPTCMgr.REST_OBJECT_RETURN, (String)result);
			
		}
			break;
		 
		default:
			break;
		}

		return resultData;
	}
}
